package com.firewolf.mybatis;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

public class MainDriver {
	@Test
	public void testQryUserById() throws IOException{
		//1.创建一个SqlSessionFactory，这里有多种方式
		Reader reader = Resources.getResourceAsReader("conf.xml");
		SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader);
		
		//3.打开一个SqlSession
		SqlSession session = factory.openSession();
		
		//4.获取查询语句，是通过sql映射文件的命名空间和select的id来定位的来
		String statement = "userMapper.qryUserById";
		
		User user = session.selectOne(statement, 1);
		System.out.println(user);
		
		//5.关闭Session
		session.close();
	}
}
